import java.util.Scanner;


public class Main {

    public static void main(String[] args) {
        int[] a = new int[]{0,7,1,6};
        int[] b = new int[]{1,5,0,6};
        int n = 4;
        findMinimum(n,a,b);

        }
    public  static void  findMinimum(int n, int[] left, int[] right) {
        int sum = 0;
        int totall = 0;
        int totalr = 0;
        int minl = 0;
        int minr = 0;
        int i = 0;
        for(i = 0; i < n;i++){
            if(left[i] != 0){
                minl = left[i];
                break;
            }
        }
        for(i = 0; i < n;i++){
            if(right[i] != 0){
                minr = right[i];
                break;
            }
        }
        for (i = 0; i < left.length; i++) {
            if (left[i] == 0 ) {
                sum += right[i];
            } else if (right[i] == 0) {
                sum += left[i];
            } else {
                totall += left[i];
                totalr += right[i];
                if(minl < left[i]){
                    minl = left[i];
                }
                if(minr < right[i]){
                    minr = right[i];
                }
            }
        }
        int ret = ((totall - minl) < (totalr - minr)) ? (totall - minl+1):(totalr - minr +1);
        sum += 1;
        ret += 1;
        ret += sum;
        System.out.println(ret );
    }
}
